<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对单个单元格的内容水平对齐</title>
</head>

<body>
    <table border="1">
        <tr>
            <th>第一个名称</th>
            <th>下一个名称</th>
        </tr>
        <tr>
            <td id="td1">Peter</td>
            <td id="td2">Griffin</td>
        </tr>
    </table>
    <br>
    <input type="button" onclick="alignCell()" value="右对齐单元格" />
    <script>
        function alignCell() {
            document.getElementById('td1').align = "right";
            document.getElementById('td2').align = "right";
        }
    </script>
</body>

</html>